<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 法大大接口控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\exception\LogicException;
use common\service\FDDService;
use think\Request;

class FDDController extends VerifyController
{
    /**
     * @var \common\service\FDDService
     */
    protected $fddService;

    public function __construct()
    {
        parent::__construct();
        $this->fddService = new FDDService();
    }


    /**
     * 获得租户实名认证地址
     * @param Request $request
     * @return \think\Response
     */
    public function getTenantRealNameAuthUrl(Request $request)
    {
        try {
            $param = $request->param();
            $res = $this->fddService->getTenantRealNameAuthUrl($param['param']);
            return json(success_response('', $res));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 实名认证回调
     * @param Request $request
     * @return \think\Response
     * @throws \think\Exception
     */
    public function authCallBack(Request $request)
    {
        try {
            $res = $this->fddService->authCallBack($request->post());
            return json(success_response("", $res));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 获得个人实名认证地址
     * @param Request $request
     * @return \think\Response
     */
    public function getUserRealNameAuthUrl(Request $request)
    {
        try {
            $param = $request->param();
            $res = $this->fddService->getUserRealNameAuthUrl($param['param']);
            return json(success_response('', $res));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 查询租户法大大证书信息
     * @param Request $request
     * @return \think\Response
     */
    public function getTenantQueryCert(Request $request)
    {
        try {
            $param = $request->param();
            $res = $this->fddService->getTenantQueryCert($param['param']['tenant_id']);
            return json(success_response('', $res));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    public function authorization(Request $request)
    {
        try {
            $res = $this->fddService->authorization($request->param());
            return json(success_response('', $res));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }
}